package example;

abstract class Food
{
   protected String name;
   public String getName()
   {
       return name;
   }
   public void setName(String name)
   {
       this.name = name;
   }
}
class Fish extends Food
{
    public Fish(String name)
    {
        this.name = name;
    }
}
class Bone extends Food
{
    public Bone(String name)
    {
        this.name = name;
    }
}
interface Animal
{
    void eat(Food food);
}
class Cat implements Animal
{
    public void eat(Food food)
    {
        System.out.println("小猫吃" + food.getName());
    }
}
class Dog implements Animal
{
    public void eat(Food food)
    {
        System.out.println("小狗吃" + food.getName());
    }
}
class Feeder
{
    public void feed(Animal animal,Food food)
    {
        animal.eat(food);
    }
}
public class TestFeeder {
    public static void main(String[] args) {
        Feeder feeder = new Feeder();
        Animal animal = new Dog();// 可以使用子类的覆盖方法
        Food food = new Bone("肉骨头");// 通过子类，使父类的name为肉骨头
        feeder.feed(animal,food);
        animal = new Cat();
        food = new Fish("鱼");
        feeder.feed(animal,food);
    }
}
